<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	 <meta charset="utf-8">
	 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	 <title th:replace="common/base::pagetitle"></title>
	 <link th:replace="common/base::static"/>
	 <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/material/easyui.css}">
	 <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/icon.css}">
	 <link rel="stylesheet" th:href="@{/static/css/wlb-treegrid.css}">
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
	 <div class="layui-row">
		  <!-- 主要内容块 -->
		  <div class="layui-col-md12" id="kMainContentCol">
				<div class="layui-fluid wlb-fluid-padding15">
					 <div class="layui-card">
						  <form>
								<div class="layui-form layui-card-header wlb-card-header-auto">
									 <div class="layui-form-item">
										  <div class="layui-inline">
												<label class="layui-form-label">名称</label>
												<div class="layui-input-inline">
													 <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">
												</div>
										  </div>
										  <div class="layui-inline">
												<button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
													 <i class="layui-icon layui-icon-search"></i>
												</button>
												<button class="layui-btn " type="reset">
													 <i class="layui-icon layui-icon-refresh-1"></i>
												</button>
										  </div>
									 </div>
								</div>
						  </form>

						  <div class="layui-card-body">
								<table id="kContentTable" lay-filter="kContentTable"></table>
						  </div>
					 </div>

				</div>
		  </div>
	 </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script th:src="@{/static/plugins/easyui/easyloader.js}"></script>

<script type="text/html" id="statusTpl">
	 {{# if(d.status === 0) { }}
	 <span class="layui-badge layui-bg-green">正常</span>
	 {{# } else { }}
	 <span class="layui-badge layui-bg-gray">禁用</span>
	 {{# } }}
</script>

<script type="text/html" id="typeTpl">
	 {{#  if(d.type === 0){ }}
	 <span class="layui-badge layui-bg-blue">供应商</span>
	 {{#  } else if(d.type === 1) { }}
	 <span class="layui-badge layui-bg-orange">核心企业</span>
	 {{#  } else if(d.type === 2) { }}
	 <span class="layui-badge layui-bg-green">银行</span>
	 {{#  } else { }}
	 <span class="layui-badge layui-bg-cyan">其他</span>
	 {{# } }}
</script>

<script type="text/html" id="sourceTpl">
	{{#  if(d.source == 0){ }}
	<span class="layui-badge layui-bg-blue">集采推送</span>
	{{#  } else if(d.source == 1) { }}
	<span class="layui-badge layui-bg-orange">其他</span>
	{{# } }}
</script>



<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
	<button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
	<button class="layui-btn layui-btn-sm" lay-event="batchdel">删除</button>
</script>


<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
	 <!--创建签名账号-->
	 {{# if(d.accountId == null || d.accountId.length == 0){ }}
	 	<a class="layui-btn layui-btn-warm layui-btn-xs"  data-event="sign" onclick="active.sign(this)" data-id="{{d.id}}"><i class="layui-icon layui-icon-friends"></i>创建签章账号</a>
	 {{#  } else { }}
	 	<a class="layui-btn layui-btn-danger layui-btn-xs"  data-event="cancel" onclick="active.cancel(this)" data-id="{{d.id}}"><i class="layui-icon layui-icon-delete"></i>注销签章账号</a>
	 	<a class="layui-btn layui-btn-normal layui-btn-xs"  data-event="info" onclick="active.info(this)" data-id="{{d.id}}"><i class="layui-icon layui-icon-form"></i>查看签章账号</a>
	 {{# } }}
</script>

<script type="text/javascript" th:inline="none">
    var active;
    layui.use(['element', 'form', 'layer', 'table', 'laytpl'], function () {
		var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
		var tableId = 'kContentTable';

		// 实例化table
		var tableIns = table.render($.extend(config.layui.table, {
			elem: '#' + tableId
			, url: api.sys.deptListData //数据接口
			//, toolbar: '#headToolbarTpl'
			, cols: [[ //表头
				{type: 'checkbox', fixed: 'left'}
				, {field: 'name', title: '机构名称', width: 120, fixed: false}
            , {field: 'accountId', title: '签名账号',  width: 180}
				, {field: 'type', title: '类型', width: 100, align: 'center', templet: '#typeTpl', fixed: false}
				, {field: 'comAddress', title: '公司地址',  width: 220, fixed: false}
				, {field: 'comCerNo', title: '工商注册号',  width: 220, fixed: false}
				, {field: 'source', title: '机构来源',  width: 100, templet: '#sourceTpl', fixed: false}
				, {field: '', title: '操作', width: 370, fixed: 'right', templet: '#rowToolbarTpl'}
			]]
		}));
		var area = ['550px', '530px'];

        // 监听事件
        active = {
            edit: function (that) {
                var id = $(that).data('id');
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: api.sys.deptEditView + '?id=' + id
                    , maxmin: true
                    , area: area   // 宽高
					, btn: ['确定', '取消']
					, yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#kFormSubmit");
                        submit.click();
                    }
                });
            },
            sign: function (that) {
                var id = $(that).data('id');
                layer.open({
                    type: 2
                    , title: '创建签章账号'
                    , content: BASE_WEB + 'esign/org/create/view?id=' + id
                    , maxmin: true
                    , area: area   // 宽高
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#kFormSubmit");
                        submit.click();
                        table.reload(tableId);
                    }
                });
            },
            cancel: function (that) {
                var id = $(that).data('id');
                layer.confirm('确定注销签章账号吗？', function (index) {
                    wlbKit.aPost(BASE_WEB + 'esign/org/cancel', {"id": id}, function (r) {
                        if (r.code === req.status.ok) {
                            table.reload(tableId);
                            wlbKit.sucessMsg('注销成功');
                        } else {
                            wlbKit.errorMsg(r.msg);
                        }
                    });
                });
            },
            info: function (that) {
                var id = $(that).data('id');
                layer.open({
                    type: 2
                    , title: '查看签章账号'
                    , content: BASE_WEB + 'esign/org/info?id=' + id
                    , maxmin: true
                    , area: area   // 宽高
                    , btn: ['取消']
                });
            }
        };

        wlbKit.activeInit(active);

        $(window).resize(function () {
            treeGridKit.fitRightFrozenCol(tableId);
        });

        // 列格式化函数
        var formatter = {
            rowToolbar: function (value, row, index) {
                return wlbKit.renderTpl('rowToolbarTpl', row);
            },
            status: function (value, row, index) {
                return wlbKit.renderTpl('statusTpl', row);
            },
            type: function (value, row, index) {
                return wlbKit.renderTpl('typeTpl', row);
            },
			source: function (value, row, index) {
				return wlbKit.renderTpl('sourceTpl', row);
			}
        };

        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params); //

			tableIns.reload({
				where: params,
				page: {curr: 1}
			});
			return false;

        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();

    });
</script>

</body>
</html>
